﻿@model ThaireInvestmentWeb.Models.EditUnitTrustHeaderModel
@{
    ViewBag.Title = "Unit Trust Header";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<script>
    $(document).ready(function () 
    {
        //alert(parseFloat("23,546,546.58".replace(',', '')));
       
        if ($("#UpdateMode").val() == '' || $("#UpdateMode").val().toLowerCase() == 'false' || 'true' != '@ViewBag.UpdateMode'.toLowerCase())
            $("#btnProportion").hide();
        if ( 'true' == '@ViewBag.UpdateMode'.toLowerCase())
            $("#btnProportion").show();
        
        $("#Header_MaturityDate,#BidOrNaveDate,#Header_ParDate").datepicker(
            {
                dateFormat: 'dd/mm/yy',
                yearRange: "-30:+40",
                isBuddhist: true,
                showOn: 'button',
                showAnim: 'fadeIn',
                changeMonth: true,
                changeYear: true,
                showButtonPanel: true,
                buttonImage: '@Url.Content("~/Content/images/Calendar.png")',
                onSelect: function(dateText, inst) { 
                    if(this.id == "Header_MaturityDate")
                    {
                        //    alert(dateText);
                        getMaturityStatus(dateText);
                    }
                }
            }
        );
        $("#CancelBtn").click(function (event)
        {
            //showConfirm("Are you sure to cancel ?", CancelBtnAction);
            showConfirm(null, CancelBtnAction);
            return false;
        });
        
        $( "#historyOfParDialog" ).dialog({
            width: 500,
            autoOpen : false ,
            modal: true, 
            position: ['center',100] ,
            buttons: {
                close: function() { 
                    $(this).dialog("close"); 
                }
            }
        });
        $( "#historyOfBidOrNavDialog" ).dialog({
            width: 500,
            autoOpen : false ,
            modal: true, 
            position: ['center',100] ,
            buttons: {
                close: function() { 
                    $(this).dialog("close"); 
                }
            }
        });
        $("#historyOfParDialog").parent().children().children('.ui-dialog-titlebar-close').hide();
        $("#historyOfBidOrNavDialog").parent().children().children('.ui-dialog-titlebar-close').hide();
        
      @*  $('#FundName').autocomplete({ 
            source: '@Url.Action("GetFundThNameAutocomplete", "UnitTrust")" + "?lang=TH' 
        }); 
        $('#FundNameEn').autocomplete({ 
            source: '@Url.Action("GetFundEnNameAutocomplete", "UnitTrust")" + "?lang=EN' 
        }); *@
        $("#FundName").autocomplete({
            source: function(request,response) {
                $.ajax({
                    url: "@(Url.Action("GetFundThNameAutocomplete", "UnitTrust"))"+ "?name=" + $("#FundName").val(),
                    type: "POST",
                    dataType: "json",
                    success: function (data) {
                        response($.map(data, function (item) {
                            return { label: item, value: item };
                        }))
                    }
                })
            }
        });
        $("#FundNameEn").autocomplete({
            source: function(request,response) {
                $.ajax({
                    url: "@(Url.Action("GetFundEnNameAutocomplete", "UnitTrust"))"+ "?name=" + $("#FundNameEn").val(),
                    type: "POST",
                    dataType: "json",
                    success: function (data) {
                        response($.map(data, function (item) {
                            return { label: item, value: item };
                        }))
                    }
                })
            }
        });
        changeListedStatus($("#SelectedListedStatus").val());
        
        $("#BidOrNavePrice").change(FormatNumber2Digits);
        $("#Header_InitialPar").change(FormatNumber2Digits);
        $("#Header_Par").change(FormatNumber2Digits);  
        $("#Header_TotalSize").change(FormatCurrencyNoDigits);
    }); 
    function CancelBtnAction(event)
    {
        window.location.href= 'ManageUnitTrust';
    }
    function getMaturityStatus(value)
    {
        $.ajax({
            url: "@Url.Action("GetMaturityStatus", "UnitTrust")" + "?maturityDate=" + value,
            type: 'POST',
            success: function(data) {
                $('#Header_MaturityStatus').val(data.MaturityStatus);
                return false;
            }
        });
    }
    function getInvolvedType(id)
    {
        $.ajax({
            url: "@Url.Action("GetInvolvedType", "UnitTrust")" + "?id=" + id,
            type: 'POST',
            success: function(data) {
                $('#InvolvedPartyTypeNo').val(data.InvolvedPartyTypeCode);
                $('#InvolvedPartyTypeReferance').val(data.InvolvedPartyTypeReference);
                return false;
            }
        });
    }
    function openParHistory(){
        $("#historyOfParDialog").dialog('option', 'title','Par Histories');
        $("#historyOfParDialog").dialog('open');
    }
    function openhistoryOfBidOrNavHistory(){
        $("#historyOfBidOrNavDialog").dialog('option', 'title','Bid or Nav Histories');
        $("#historyOfBidOrNavDialog").dialog('open');
    }
    function changeListedStatus(value)
    {
        //alert("test1" + value);
        if (value != '' && value != null) {  
            if (value == 'LISTED') {               
                $('#lblBidOrNav').text('Bid Price');
                $('#lblBidOrNavAsOF').text('Bid Price as of');
            }
            else {
                $('#lblBidOrNav').text('NAV');
                $('#lblBidOrNavAsOF').text('NAV as of');
            }
        }                                
    }
</script>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>

<div id="historyOfParDialog" style="display: none">
    @if (Model.ScreenData != null && Model.ScreenData.HeaderDTO != null)
    {
        @Html.Partial("_UnitTrustParView", Model.ScreenData.HeaderDTO)
    }
    else
    {
        <label>Data not found.</label>
    }
</div>
<div id="historyOfBidOrNavDialog" style="display: none">
    @if (Model.ScreenData != null && Model.ScreenData.HeaderDTO != null)
    {
        @Html.Partial("_UnitTrustBidOrNavView", Model.ScreenData.HeaderDTO)
    }
    else
    {
        <label>Data not found.</label>
    }
</div>

<table class="navi" width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr>
        <td style="width: 100%;">
            <div class="navi">
                Instrument Type > <a href="@Url.Action("ManageUnitTrust", "UnitTrust", new { headerId = @Model.HeaderID })">Unit Trust</a> > Header
          
            </div>
        </td>
    </tr>
</table>

<table class="tableheader" width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr>
        <td height="38" align="center" style="width: 100%; text-align: center;">INPUT Unit Trust</td>
    </tr>
</table>

<table width="951" border="0" align="center">
    <tr>
        <td>
            @using (Html.BeginForm("EditUnitTrustHeader", "UnitTrust", FormMethod.Post, new { id = "mainForm" }))
            {
                @Html.ValidationSummary(true)

                <table width="100%" border="0" align="center" cellspacing="2">
                    <tr>
                        <td width="300" height="31">&nbsp;</td>
                        <td align="right">
                            <div style="text-align: right">Create by : @Model.Header.CreateBY </div>
                        </td>
                        <td width="5">&nbsp;</td>
                        <td width="139" align="right">
                            <div style="text-align: right">Create Time :@Model.Header.CreateDate</div>
                        </td>
                    </tr>
                    <tr>
                        <td width="300" height="31">&nbsp;</td>
                        <td align="right">
                            <div style="text-align: right">Update by : @Model.Header.ModifyBY</div>
                        </td>
                        <td width="5">&nbsp;</td>
                        <td width="139" align="right">
                            <div style="text-align: right">Update Time :@Model.Header.ModifyDate</div>
                        </td>
                    </tr>
                </table>
                <table class="tableform" width="100%" border="5" align="center" cellspacing="2">
                    <tr>
                        <td width="212">
                            <div align="right">Company Name <span class="error">*</span> : </div>
                        </td>
                        <td>&nbsp;</td>
                        <td style="width: 236px">@Html.DropDownListFor(x => x.SelectedCompany, Model.CompanyList)</td>
                        <td width="188" align="right">
                            <div align="right">Maturity Status:</div>
                        </td>
                        <td>&nbsp;</td>
                        <td width="208">
                            @Html.TextBoxFor(model => model.Header.MaturityStatus, new { @readonly = "readonly" })
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <div align="right">Type : </div>
                        </td>
                        <td>&nbsp;</td>
                        <td style="width: 236px">@Html.DropDownListFor(x => x.SelectedType, Model.TypeList)</td>
                        <td>
                            <div align="right">Group of Type : </div>
                        </td>
                        <td>&nbsp;</td>
                        <td style="width: 236px">
                            @Html.DropDownListFor(x => x.SelectedGroupOfType, Model.GroupOfTypeList)</td>
                    </tr>
                    <tr>
                        <td>
                            <div align="right">
                                Fund Name(TH) <span class="error">*</span>
                                :
                            </div>
                        </td>
                        <td>&nbsp;</td>
                        <td style="width: 236px">
                            @Html.TextBoxFor(model => model.FundName, new { style = "width:350px", maxlength = 80 })
                            @Html.ValidationMessageFor(model => model.FundName)</td>
                        <td></td>
                        <td>&nbsp;</td>
                        <td></td>
                    </tr>
                    <tr>
                        <td>
                            <div align="right">
                                Fund Name(EN) <span class="error">*</span> :
                            </div>
                        </td>
                        <td>&nbsp;</td>
                        <td style="width: 236px">
                            @Html.TextBoxFor(model => model.FundNameEn, new { style = "width:350px", maxlength = 80 })
                            @Html.ValidationMessageFor(model => model.FundNameEn)</td>
                        <td>
                            <div align="right"></div>
                        </td>
                        <td>&nbsp;</td>
                        <td></td>
                    </tr>
                    <tr>
                        <td style="height: 4px"></td>
                        <td style="height: 4px"></td>
                        <td style="width: 236px; height: 4px;"></td>
                        <td style="height: 4px"></td>
                        <td style="height: 4px"></td>
                        <td style="height: 4px"></td>
                    </tr>
                    <tr>
                        <td>
                            <div align="right">
                                Asset Management <span class="error">*</span>
                                :
                            </div>
                        </td>
                        <td>&nbsp;</td>
                        <td style="width: 236px">
                            @Html.DropDownListFor(x => x.SelectedAssetManagementCompany, Model.AssetManagementCompanyList)
                            &nbsp;</td>
                        <td><div align="right">Listed Status <span class="error">*</span> :</div></td>
                        <td> &nbsp; 
                            
                        </td>
                        <td>@Html.DropDownListFor(x => x.SelectedListedStatus, Model.ListedStatusList, new { onchange = "changeListedStatus(this.value)" })
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <div align="right">
                                Symbol <span class="error">*</span>
                                :
                            </div>
                        </td>
                        <td>&nbsp;</td>
                        <td style="width: 236px">
                            @Html.TextBoxFor(model => model.Symbol)
                            @Html.ValidationMessageFor(model => model.Symbol)

                        </td>
                        <td>
                            <div align="right">Total size : </div>
                        </td>
                        <td>&nbsp;</td>
                        <td>
                            @Html.TextBoxFor(model => model.Header.TotalSize, new {@class = "inputNumberField",  style = "width: 100px;", })
                            @Html.ValidationMessageFor(model => model.Header.TotalSize)

                        </td>
                    </tr>
                    <tr>
                        <td>
                            <div align="right">Maturity Date  : </div>
                        </td>
                        <td>&nbsp;</td>
                        <td style="width: 236px">
                            @Html.TextBoxFor(model => model.Header.MaturityDate, new { style = "width: 100px;", @Value = ThaireInvestmentWeb.Util.WebUtil.FormatDate(@Model.Header.MaturityDate) })
                            @Html.ValidationMessageFor(model => model.Header.MaturityDate) (Ex.31/12/2014)
                        </td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>

                            <input type="button" id="btnProportion" name="btnProportion" value="สัดส่วนการลงทุน " class="button" onclick="go('@Url.Action("EditUnitTrustProportion", "UnitTrust", new { headerId = Model.Header.ID.ToString() })    ');">
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <div align="right">
                                <label id="lblBidOrNav" name="lblBidOrNav">Bid Price / NAV<span class="error">*</span></label>
                                :
                            </div>
                        </td>
                        <td>&nbsp;</td>
                        <td style="width: 236px">
                            @Html.TextBoxFor(model => model.BidOrNavePrice, new { style = "width: 100px;", @class = "inputNumberField", @Value = ThaireInvestmentWeb.Util.WebUtil.FormatCurrency2(@Model.BidOrNavePrice) })
                            @Html.ValidationMessageFor(model => model.BidOrNavePrice)
                            &nbsp;
                            
                           

                            <input type="button" name="Submit23" value=" history " class="button" onclick="openhistoryOfBidOrNavHistory();return false;">
                        </td>
                        <td style="height: 4px">
                            <div align="right">Initial Par : </div>
                        </td>
                        <td style="height: 4px"></td>
                        <td style="width: 236px; height: 4px;">
                            @Html.TextBoxFor(model => model.Header.InitialPar, new { style = "width: 100px;", @class = "inputNumberField", @Value = ThaireInvestmentWeb.Util.WebUtil.FormatCurrency2(@Model.Header.InitialPar) })
                            @Html.ValidationMessageFor(model => model.Header.InitialPar)</td>
                    </tr>
                    <tr>
                        <td style="height: 4px">
                            <div align="right">
                                <label id="lblBidOrNavAsOF" name="lblBidOrNavAsOF">Bid Price as of / NAV as of</label>
                                : 
                            </div>
                        </td>
                        <td style="height: 4px">&nbsp;</td>
                        <td style="width: 236px; height: 4px;">
                            @*                            @Html.TextBoxFor(model => model.BidOrNaveDate, new { @readonly = "readonly", @Value = ThaireInvestmentWeb.Util.WebUtil.FormatDate(@Model.BidOrNaveDate) })*@
                            @Html.TextBoxFor(model => model.BidOrNaveDate, new {style = "width: 100px;",  @Value = ThaireInvestmentWeb.Util.WebUtil.FormatDate(@Model.BidOrNaveDate) })
                            @Html.ValidationMessageFor(model => model.BidOrNaveDate) (Ex.31/12/2014)</td>
                        <td style="height: 4px">
                            <div align="right">Par : </div>
                        </td>
                        <td style="height: 4px"></td>
                        <td style="width: 236px; height: 4px;">
                            @Html.TextBoxFor(model => model.Header.Par, new { style = "width: 100px;", @class = "inputNumberField", @Value = ThaireInvestmentWeb.Util.WebUtil.FormatCurrency2(@Model.Header.Par) })
                            @Html.ValidationMessageFor(model => model.Header.Par)

                            <input type="button" name="Submit25" value=" history " class="button" onclick="openParHistory();return false;">
                        </td>
                    </tr>
                    <tr>
                        <td style="height: 4px">
                            <div align="right">@*Cost NAV   :*@ </div>
                        </td>
                        <td style="height: 4px"></td>
                        <td style="width: 236px; height: 4px;">
                            @*<input name="date_buy28" type="text" id="date_buy28"
                                style="text-align: center" value="" size="10" readonly="readonly">*@</td>
                        <td style="height: 4px">
                            <div align="right">Par as of : </div>
                        </td>
                        <td style="height: 4px">&nbsp;</td>
                        <td style="width: 236px; height: 4px;">
                            @Html.TextBoxFor(model => model.Header.ParDate, new { style = "width: 100px;", @Value = ThaireInvestmentWeb.Util.WebUtil.FormatDate(@Model.Header.ParDate) })
                            @Html.ValidationMessageFor(model => model.Header.ParDate) </td>
                    </tr>
                    <tr>
                        <td>
                            <div align="right">Liquidity    : </div>
                        </td>
                        <td>&nbsp;</td>
                        <td colspan="4">

                            @Html.CheckBoxFor(model => model.IsTierISelected)

                            Tier I&nbsp; 

                            @Html.TextBoxFor(model => model.Header.LiquidityTierIPercent, new { @class = "inputNumberField", @Value = ThaireInvestmentWeb.Util.WebUtil.FormatDecimal2DigitFree(@Model.Header.LiquidityTierIPercent) })
                            @Html.ValidationMessageFor(model => model.Header.LiquidityTierIPercent)
                            %
                            <br />
                            @Html.CheckBoxFor(model => model.IsTierIISelected)

                            Tier II&nbsp;

                            @Html.TextBoxFor(model => model.Header.LiquidityTierIIPercent, new { @class = "inputNumberField", @Value = ThaireInvestmentWeb.Util.WebUtil.FormatDecimal2DigitFree(@Model.Header.LiquidityTierIIPercent) })
                            @Html.ValidationMessageFor(model => model.Header.LiquidityTierIIPercent)
                            %
                            <br />
                            @Html.CheckBoxFor(model => model.IsLowLiquiditySelected)
                            Low Liquidity&nbsp;
                            @Html.TextBoxFor(model => model.Header.LiquidityLowLiquidityPercent, new { @class = "inputNumberField", @Value = ThaireInvestmentWeb.Util.WebUtil.FormatDecimal2DigitFree(@Model.Header.LiquidityLowLiquidityPercent) })
                            @Html.ValidationMessageFor(model => model.Header.LiquidityLowLiquidityPercent)
                            %
                            <br />
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <div align="right">Involved Party Type Name    : </div>
                        </td>
                        <td>&nbsp;</td>
                        <td style="width: 236px">
                            @Html.DropDownListFor(x => x.SelectedInvolvedPartyType, Model.InvolvedPartyTypeNameList, new { onchange = "getInvolvedType(this.value)" })
                        </td>
                        <td>
                            <div align="right">Involved Party Type No. : </div>
                        </td>
                        <td>&nbsp;</td>
                        <td>
                            @Html.TextBoxFor(model => model.InvolvedPartyTypeNo, new { @readonly = "readonly" })
                        </td>
                    </tr>
                    @* <tr>
                        <td>
                            <div align="right">รหัสอ้างอิง คปภ. (A-E)    : </div>
                        </td>
                        <td>&nbsp;</td>
                        <td style="width: 236px">
                            @Html.TextBoxFor(model => model.InvolvedPartyTypeReferance, new { @readonly = "readonly" })
                        </td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                    </tr>*@
                    <tr>
                        <td>
                            <div align="right">Relate    : </div>
                        </td>
                        <td>&nbsp;</td>
                        <td style="width: 236px">
                            @Html.DropDownListFor(x => x.SelectedRelatedOrNonRelated, Model.RelatedOrNonRelatedList)

                        </td>
                        <td>
                            <div align="right">Remark (OIC)    : </div>
                        </td>
                        <td>&nbsp;</td>
                        <td>@Html.TextBoxFor(model => model.Header.RemarkOic)
                            @Html.ValidationMessageFor(model => model.Header.RemarkOic)
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <div align="right"></div>
                        </td>
                        <td>&nbsp;</td>
                        <td style="width: 236px">&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                    </tr>
                </table>

                <table width="95%" border="0" align="center" style="height: 38px">

                    <tr>


                        <td style="height: 38px">
                            <div align="center">
                                <input id="SaveBtn" type="submit" name="SaveBtn" value=" Submit " class="button" need-confirm="true">
                                &nbsp;&nbsp; 
                                <input id="CancelBtn" type="button" name="CancelBtn" value=" Cancel " class="button">
                                &nbsp;&nbsp;
                                <input id="EditBtn" type="button" name="EditBtn" value=" Edit " class="button">
                            </div>
                        </td>
                    </tr>

                </table>
                
                if (Model.UpdateMode)
                {
                <table width="95%" border="0" align="center">
                    <tr>
                        <td>
                            <div align="center" style="text-align: left">
                                <input type="button" name="PurchaseBtn" value=" Purchase / Subscription " class="button" onClick="go('@Url.Action("AddPurchaseTransaction", "UnitTrust", new { headerId = Model.Header.ID.ToString() })    ');" >
                                &nbsp;&nbsp; 
                                <input type="button" name="Submit42" class="btsub" value="  Sale  " onClick="go('@Url.Action("AddSaleTransaction", "UnitTrust", new { headerId = Model.Header.ID.ToString() })    ');" >
                                &nbsp;&nbsp; 
                                <input type="button" name="Submit422" class="btsub" value="  Guarantee  " onClick="go('@Url.Action("AddGuaranteeTransaction", "UnitTrust", new { headerId = Model.Header.ID.ToString() })    ');" >
                                &nbsp;&nbsp;
                                @*<input type="button" name="Submit422" class="btsub" value=" สิทธิประโยชน์ " />*@
                                <input type="button" name="Submit422" class="btsub" value=" สิทธิประโยชน์ " onClick="go('@Url.Action("ManageUnitTrustPrivilege", "UnitTrust", new { headerId = Model.Header.ID.ToString() })    ');" >
                            </div>
                        </td>
                    </tr>
                </table>

                }
                @Html.HiddenFor(x => x.UpdateMode)
                @Html.HiddenFor(x => x.HeaderID)
            }

            <div style="width: 930px; overflow: auto;">
                @if (Model.TransactionAdaters != null)
                {
                    var grid = new WebGrid(source: Model.TransactionAdaters);
                    @grid.GetHtml(tableStyle: "tablelist", headerStyle: "headertable", displayHeader: @Model.TransactionAdaters.Count > 0,
            columns: grid.Columns(
                grid.Column(header: "NO.", format: item => item.WebGrid.Rows.IndexOf(item) + 1, canSort: false),
                grid.Column(columnName: "TransactionType", header: "Purchase/Sale/Guarantee", canSort: false),
                grid.Column(columnName: "FundName", header: "Fund Name", canSort: false),
                grid.Column(columnName: "TimeToMaturityDate", header: "Time to Maturity Date", canSort: false),
                grid.Column(columnName: "TradeDate", header: "TradeDate", canSort: false),
                grid.Column(columnName: "SettlementDate", header: "Settlement Date", canSort: false),
 grid.Column(header: "Detail", format:
                        @<text>
                    <input type="image" onClick="go('@item.Link    ');return false;"  src="@Url.Content("~/Content/images/b_edit.gif")"  title="แก้ไข (update)">
                    </text>))
                );
                }
            </div>
            <br>
        </td>
    </tr>
</table>

